<template>
	<view class="template">
		<cu-custom :bgColor="'bg-'+theme.backgroundColor" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">分销员列表</block>
		</cu-custom>
		<view class="cu-bar fixed goods-search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input v-model="searchKeyword" type="text" placeholder="请输入员工姓名" confirm-type="search"
					@confirm="searchClick"></input>
				<text @click="searchClick" class="text-sm" :class="'text-'+theme.themeColor"
					style="margin-right: 30rpx;">搜索</text>
			</view>
		</view>
		<view class="mTop-100">
			<view class="mInfo">
				<view v-for="(item,index) in memberList" :key="index" class="mItem" @click="jumpOrderList(item)">
					<view class="flex align-center">
						<view>{{item.userName}}</view>
						<view class="text-gray3">（{{item.phone}}）</view>
					</view>
					<view class="cuIcon-right"></view>
				</view>
			</view>
			<view class="cu-load" v-if="!loading && !memberList.length">暂无员工</view>
			<view class="cu-load loading" v-if="loading"></view>
			<view class="cu-load" v-if="!loadmore && !loading && memberList.length && memberList.length>10">没有更多了</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	import api from 'utils/api'

	export default {
		name: 'yc-distributors',
		data() {
			return {
				theme: app.globalData.theme, //全局颜色变量
				CustomBar: this.CustomBar,
				memberList: [], // 分销员列表
				loading: false,
				page: {},
				loadmore: true,
				searchKeyword: '',
				type: null, // 从搜索页跳转而来 
			}
		},
		onLoad(options) {
			this.type = options.type || null
			this.userInfo = uni.getStorageSync('user_info')
			if (this.userInfo && this.userInfo.id) {
				this.page.leaderUserid = this.userInfo.id
				this.getList()
			}
		},
		// onReachBottom() {
		// 	if (this.loadmore) {
		// 		this.page.current = this.page.current + 1;
		// 		this.getList();
		// 	}
		// },
		methods: {
			getList() {
				this.loading = true
				api.ycSpreadUsers(this.page).then(res => {
					this.memberList = res.data || []
				}).finally(() => {
					this.loadmore = false
					this.loading = false
				})
			},
			jumpOrderList(item) {
				if (this.type == 1) {
					var pages = getCurrentPages(); // 获取页面栈
					var prevPage = pages[pages.length - 2]; // 上一个页面
					prevPage.$vm.getsName({
						userid: item.userid,
						userName: item.userName
					});
					uni.navigateBack({
						delta: 1
					});
				} else {
					uni.navigateTo({
						url: '/pages/actYc/yc-disOrderList?userid=' + item.userid + '&userName=' + item.userName
					})
				}

			},
			// 搜索
			searchClick() {
				this.page.userName = this.searchKeyword
				this.getList()
			},
		}
	}
</script>

<style scoped>
	.mInfo {
		background-color: #fff;
	}

	.mInfo .mItem {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		padding: 0 30rpx;
		border-bottom: 1rpx solid #f3f3f3;
	}

	.goods-search {
		top: unset !important;
		height: 100rpx
	}
</style>